package sunyu.controller.common;

import org.slf4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import sunyu.controller.common.property.editor.DateTimePropertyEditorSupport;
import sunyu.kit.common.LogKit;

import java.util.Date;

/**
 * 公共controller
 * <p>
 * 所有controller项目都需要依赖此项目
 * <p>
 * 继承此类，就可以获得日期类型自动转换功能
 *
 * @author 孙宇
 */
@Controller
@RequestMapping("/")
public class CommonController {

    private static final Logger logger = LogKit.getLogger();

    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        /**
         * 自动转换日期类型的字段格式
         */
        binder.registerCustomEditor(Date.class, new DateTimePropertyEditorSupport());
    }

    /**
     * 跳转到index页面
     *
     * @return
     */
    @RequestMapping("/index")
    public String index() {
        return "/index";
    }

}
